/**
 * Copyright 2019 [shujiang.yang], Inc. All rights reserved.
 * Email: 314938230@qq.com
**/
define("pages/jbjl/jbjl_dynamic", [
        "../../common/componts.js",
        "../../plugins/easyui/jquery-easyui-1.5.1/jquery.easyui.min",
        "../../plugins/easyui/jquery-easyui-1.5.1/easyloader",
        "../../plugins/artTemplate/artTemplate"
    ],
    function(require) {
        var componts = require("../../common/componts");
        var queryTableId="awdDynamicQueryTableId";
        var selectid;

        var getQueryDataGrid = function(){
            return $("#"+queryTableId);
        };

        var tableInit=function(){
            componts.initTable(queryTableId,{
                url:"/jbjl/list",
                title:'',
                fit:true,
                // firstLoad:true,
                width:'100%',
                columns :  [
                    {field: 'id',title: '',width:30,hidden:true}
                    ,{field:'sknum',title:'剩余手铐数量',hidden:true,width:20,sortable:'true',formatter: function(value){return value?'<span title="'+value+'">'+value+'</span>':'';}}
                    ,{field:'sldly',title:'所领导留言',hidden:true,width:20,sortable:'true',formatter: function(value){return value?'<span title="'+value+'">'+value+'</span>':'';}}
                    ,{field:'lastnum',title:'上次交班人数',hidden:true,width:20,sortable:'true',formatter: function(value){return value?'<span title="'+value+'">'+value+'</span>':'';}}
                    ,{field:'mustnum',title:'当前应有人数',hidden:true,width:20,sortable:'true',formatter: function(value){return value?'<span title="'+value+'">'+value+'</span>':'';}}
                    ,{field:'currnum',title:'当前实际人数',hidden:true,width:20,sortable:'true',formatter: function(value){return value?'<span title="'+value+'">'+value+'</span>':'';}}
                    ,{field:'todayinnum',title:'今天入所人数',hidden:true,width:20,sortable:'true',formatter: function(value){return value?'<span title="'+value+'">'+value+'</span>':'';}}
                    ,{field:'todayoutnum',title:'今天出所人数',hidden:true,width:20,sortable:'true',formatter: function(value){return value?'<span title="'+value+'">'+value+'</span>':'';}}
                    ,{field:'jstzinnum',title:'拘室调整进入人数',hidden:true,width:20,sortable:'true',formatter: function(value){return value?'<span title="'+value+'">'+value+'</span>':'';}}
                    ,{field:'jstzoutnum',title:'拘室调整出去人数',hidden:true,width:20,sortable:'true',formatter: function(value){return value?'<span title="'+value+'">'+value+'</span>':'';}}
                    ,{field:'tsnum',title:'办理提审人数',hidden:true,width:20,sortable:'true',formatter: function(value){return value?'<span title="'+value+'">'+value+'</span>':'';}}
                    ,{field:'lshjnum',title:'律师会见数量',hidden:true,width:20,sortable:'true',formatter: function(value){return value?'<span title="'+value+'">'+value+'</span>':'';}}
                    ,{field:'jshjnum',title:'亲属会见数量',hidden:true,width:20,sortable:'true',formatter: function(value){return value?'<span title="'+value+'">'+value+'</span>':'';}}
                    ,{field:'lslsnum',title:'临时离所数量',hidden:true,width:20,sortable:'true',formatter: function(value){return value?'<span title="'+value+'">'+value+'</span>':'';}}
                    ,{field:'swjynum',title:'所外就医数量',hidden:true,width:20,sortable:'true',formatter: function(value){return value?'<span title="'+value+'">'+value+'</span>':'';}}
                    ,{field:'todaypjnum',title:'今天判决人数',hidden:true,width:20,sortable:'true',formatter: function(value){return value?'<span title="'+value+'">'+value+'</span>':'';}}
                    ,{field:'zdrynum',title:'重点人员数量',hidden:true,width:20,sortable:'true',formatter: function(value){return value?'<span title="'+value+'">'+value+'</span>':'';}}
                    ,{field:'zdbhnum',title:'重点病号数量',hidden:true,width:20,sortable:'true',formatter: function(value){return value?'<span title="'+value+'">'+value+'</span>':'';}}
                    ,{field:'syjjnum',title:'使用戒具人数',hidden:true,width:20,sortable:'true',formatter: function(value){return value?'<span title="'+value+'">'+value+'</span>':'';}}
                    ,{field:'jbnum',title:'禁闭人数',hidden:true,width:20,sortable:'true',formatter: function(value){return value?'<span title="'+value+'">'+value+'</span>':'';}}
                    ,{field:'ygnum',title:'严管人数',hidden:true,width:20,sortable:'true',formatter: function(value){return value?'<span title="'+value+'">'+value+'</span>':'';}}
                    ,{field:'jlnum',title:'剩余脚镣数量',hidden:true,width:20,sortable:'true',formatter: function(value){return value?'<span title="'+value+'">'+value+'</span>':'';}}
                    ,{field:'jsnum',title:'剩余警绳数量',hidden:true,width:20,sortable:'true',formatter: function(value){return value?'<span title="'+value+'">'+value+'</span>':'';}}
                    ,{field:'ysnum',title:'交班时钥匙数量',hidden:true,width:20,sortable:'true',formatter: function(value){return value?'<span title="'+value+'">'+value+'</span>':'';}}
                    ,{field:'ssdnum',title:'交班时搜索灯数量',hidden:true,width:20,sortable:'true',formatter: function(value){return value?'<span title="'+value+'">'+value+'</span>':'';}}
                    ,{field:'dtnum',title:'交班时电台数量',hidden:true,width:20,sortable:'true',formatter: function(value){return value?'<span title="'+value+'">'+value+'</span>':'';}}
                    ,{field:'jjnum',title:'警戒数量',hidden:true,width:20,sortable:'true',formatter: function(value){return value?'<span title="'+value+'">'+value+'</span>':'';}}
                    ,{field:'jbly',title:'交班留言',hidden:true,width:20,sortable:'true',formatter: function(value){return value?'<span title="'+value+'">'+value+'</span>':'';}}
                    ,{field:'flag',title:'标志',hidden:true,width:20,sortable:'true',formatter: function(value){return value?'<span title="'+value+'">'+value+'</span>':'';}}
                    ,{field:'jsbh',title:'监所编号',hidden:true,width:20,sortable:'true',formatter: function(value){return value?'<span title="'+value+'">'+value+'</span>':'';}}
                    ,{field:'gjly',title:'管教留言',hidden:true,width:20,sortable:'true',formatter: function(value){return value?'<span title="'+value+'">'+value+'</span>':'';}}
                    ,{field:'ysly',title:'医生留言',hidden:true,width:20,sortable:'true',formatter: function(value){return value?'<span title="'+value+'">'+value+'</span>':'';}}
                    ,{field:'ywyc',title:'有无异常',hidden:true,width:20,sortable:'true',formatter: function(value){return value?'<span title="'+value+'">'+value+'</span>':'';}}
                    ,{field:'jbqk',title:'交班情况',hidden:true,width:20,sortable:'true',formatter: function(value){return value?'<span title="'+value+'">'+value+'</span>':'';}}
                ] ,
                //基本信息双击事件
                onDblClickRow:function(rowIndex, rowData){
                    $("input[name='ryRadio']")[rowIndex].checked = true;
                    getQueryDataGrid().datagrid("selectRow", rowIndex);
                    selectid=rowData.id;
                },
                onLoadSuccess:function(data){
                    if(data.total>0){
                        getQueryDataGrid().datagrid("selectRow", 0);
                        $("input[name='ryRadio']")[0].checked = true;
                    }
                },
                //单击行选中取消事件
                onClickRow:function(rowIndex, rowData){
                    if(selectid!=rowData.id){
                        $("input[name='ryRadio']")[rowIndex].checked = true;
                        selectid=rowData.id;
                    }else{
                        getQueryDataGrid().datagrid("unselectRow",rowIndex);
                        $("input[name='ryRadio']")[rowIndex].checked = false;
                        getQueryDataGrid().datagrid('clearSelections');
                        selectid="";
                    }
                }
                });
                //页面高度自适应
                getQueryDataGrid().datagrid('resize',{
                    height:($(window).height()-150)
                });
            };

        /**
         * 数据列表刷新加载
         */
        var loadDataGrid = function(){
            var formData = $(".awd-dynamic-query-form").serializeObject();
            var queryParams = $.extend({},formData,{"state":"R2"});
            getQueryDataGrid().datagrid('clearSelections');
            getQueryDataGrid().datagrid('load',queryParams);
        };

        var bindAction=function(){
            //查询
            $(".awd-dynamic-query-btn").on("click",function(){
                loadDataGrid();
            });

            /**
             * 绑定回车事件
             */
            $(window).keydown(function(event) {
                if (event.keyCode == 13) {
                    loadDataGrid();
                }
            });

        };

        //初始化
        (function(){
            componts.initSelectPage(undefined);
            componts.initSelect(undefined,undefined,undefined);
            tableInit();
            bindAction();
        })()
    });
